home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4268 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Filesize
  5. Date: 29 Jan 1996 11:57:14 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4eicmq$r69@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe11.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 29, 1996 11:31:25 in article <Filesize>, 'Daniel Ponti
  15. <daniel.ponti@ubs.ch>' wrote: 
  16.  
  17.  
  18. >How can i get the size of a file in c? 
  19. >There exists one with a structure stat and a function stat, but 
  20. >this does not work under c++ (the function should also work in c++). 
  21.  
  22. I've found the following to work correctly under all platforms 
  23. with which I work: 
  24.  
  25.   1.  Open the file in binary mode using stdio fopen(); 
  26.   2.  Use fseek(FilePointer, 0L, SEEK_END); to position file at end. 
  27.   3.  Call ftell() to get the file length. 
  28.   4.  Either close the file or reset back to start with fseek() 
  29.  
  30. Note binary mode.  In text mode you get the wrong answer in DOS. 
  31.  
  32. If SEEK_END isn't defined on your machine, #define it as 2 
  33.  
  34. -- 
  35. Pete Grant 
  36. Kalevi, Inc. 
  37. Object Oriented Software Development
  38.